package com.test.shiver.controller;

import com.test.shiver.entity.User;
import com.test.shiver.service.UserService;
import com.test.shiver.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class UserListServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<User> userList = userService.GetUserList();

        if(userList == null || userList.size() == 0){
            System.out.println("size 0 ");
            return;
        }

        request.setAttribute("userList",userList);
        request.setAttribute("userCount",userList.size());
        request.setAttribute("msg",request.getParameter("msg"));
        request.getRequestDispatcher("/userList.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request,response);
    }
}
